package com.fanshuai;

import com.fanshuai.config.GitlabUtils;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.gitlab.api.models.GitlabBranch;
import org.gitlab.api.models.GitlabNamespace;
import org.gitlab.api.models.GitlabProject;

import java.util.List;

/**
 * Hello world!
 *
 */
public class App {
    public static void main(String[] args) throws Exception {
        testGitlab();
    }

    private static void testGitlab() throws Exception {
        GitlabProject gitlabProject = GitlabUtils.getProject("X", "kids-order");
        System.out.println(json(gitlabProject));

        GitlabNamespace namespace = gitlabProject.getNamespace();
        List<GitlabProject> projects = GitlabUtils.getGroupProjects(namespace.getId());
        //System.out.println(json(projects));

        List<GitlabBranch> branches = GitlabUtils.getAllBranches(gitlabProject);
        //System.out.println(json(branches));

        GitlabBranch branch = GitlabUtils.getBranch(gitlabProject, "feature/docker");
        System.out.println(json(branch));

        GitlabUtils.mergeCode(gitlabProject, "feature/docker2", branch.getCommit().getId());
    }

    private static String json(Object o) throws JsonProcessingException {
        return new ObjectMapper().writeValueAsString(o);
    }
}
